package com.dagger.weapon.controller;

import com.dagger.weapon.entity.ArticleContents;
import com.dagger.weapon.entity.SearchArticle;
import com.dagger.weapon.service.ArticleContentService;
import com.dagger.weapon.vo.ResultVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/article")
@CrossOrigin
@Api(value = "提供文章内容相关接口",tags = "文章内容管理")
public class ArticleContentController {

    @Autowired
    private ArticleContentService articleContentService;

    @ApiOperation("新建文章内容接口")
    @PostMapping("/goal")
    @ApiImplicitParams({
            @ApiImplicitParam(dataType = "ArticleContents",name = "goal",value = "文章内容对象",required = true),
            @ApiImplicitParam(dataType = "string",name = "token",value = "令牌",required = true),
    })
    public ResultVO addArticleContent(@RequestHeader("token")String token,@RequestBody ArticleContents goal){
        ResultVO resultVO = articleContentService.addArticleContent(goal);
        return resultVO;
    }

    @ApiOperation("获取文章列表")
    @GetMapping("/items")
    @ApiImplicitParams({
            @ApiImplicitParam(dataType = "SearchArticle",name = "params",value = "文章内容对象",required = false),
            @ApiImplicitParam(dataType = "string",name = "token",value = "令牌",required = true),
    })
    public ResultVO searchArticles(@RequestHeader("token")String token, SearchArticle params){
        return articleContentService.searchArticles(params);
    }

    @ApiOperation("删除指定文章")
    @DeleteMapping("/del/{aid}")
    @ApiImplicitParams({
            @ApiImplicitParam(dataType = "string",name = "token",value = "令牌",required = true),
            @ApiImplicitParam(dataType = "string",name = "aid",value = "要删除文章的主键ID",required = true),
    })
    public ResultVO DeleteArticle(@RequestHeader("token")String token,@PathVariable("aid") String aid ){
        return articleContentService.deleteArticle(aid);
    }

    @ApiOperation("查询指定文章")
    @GetMapping("/only/{aid}")
    @ApiImplicitParams({
            @ApiImplicitParam(dataType = "string",name = "token",value = "令牌",required = true),
            @ApiImplicitParam(dataType = "string",name = "aid",value = "要查询文章的主键ID",required = true),
    })
    public ResultVO onlyArticle(@RequestHeader("token")String token,@PathVariable("aid") String aid){
        return articleContentService.onlyArticle(aid);
    }

    @ApiOperation("修改指定文章")
    @PutMapping("/update")
    @ApiImplicitParams({
            @ApiImplicitParam(dataType = "string",name = "token",value = "令牌",required = true),
            @ApiImplicitParam(dataType = "ArticleContents",name = "aim",value = "修改指定id的文章内容",required = true),
    })
    public ResultVO updateArticle(@RequestHeader("token")String token,@RequestBody ArticleContents aim){
        return articleContentService.updateArticle(aim);
    }
}
